package ${package.Controller};
<#if superControllerClassPackage??>
    import ${superControllerClassPackage};
</#if>

import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.pjnkj.${package.ModuleName}.common.json.Body;
import com.pjnkj.${package.ModuleName}.common.json.Meta;
import ${package.Entity}.${entity};
import ${package.Service}.${entity}Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.pjnkj.thunder.common.json.Meta.CODE_470;
<#if restControllerStyle>
    import org.springframework.web.bind.annotation.RestController;
<#else>
    import org.springframework.stereotype.Controller;
</#if>

/**
* <p>
    * ${table.comment!} 前端控制器
    * </p>
*
* @author ${author}
* @since ${date}
*/
<#if restControllerStyle>
    @RestController
<#else>
    @Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
    class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
        public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
        public class ${table.controllerName} {
    </#if>
    @Autowired
    ${entity}Service ${entity?uncap_first}Service;

    /**
    * 删除数据
    *
    * @param ${entity?uncap_first}
    */
    @PostMapping("delete")
    public Body delete(Integer id) {
    Boolean flag = ${entity?uncap_first}Service.removeById(id);
    if (flag == true) {
    return Body.newInstance("删除成功");
    }
    return Body.newInstance(Meta.CODE_400, "删除失败");
    }

    /**
    * 增加数据
    *
    * @param ${entity?uncap_first}
    */
    @PostMapping("create")
    public Body create(@Validated(${entity}.class) @RequestBody ${entity} ${entity?uncap_first}) {
    Boolean flag = ${entity?uncap_first}Service.saveOrUpdate(${entity?uncap_first});
    if (flag == true) {
    return Body.newInstance("保存成功");
    }
    return Body.newInstance(Meta.CODE_400, "保存失败");
    }

    /**
    * 修改数据
    *
    * @param ${entity?uncap_first}
    */
    @PostMapping("update")
    public Body update(@Validated(${entity}.class) @RequestBody ${entity} ${entity?uncap_first}) {
    Boolean flag = ${entity?uncap_first}Service.updateById(${entity?uncap_first});
    if (flag == true) {
    return Body.newInstance("修改成功");
    }
    return Body.newInstance(Meta.CODE_400, "修改失败");
    }

    /**
    * 查询数据
    *
    * @param
    */
    @PostMapping("find")
    public Body find(String id) {
    ${entity} info = ${entity?uncap_first}Service.getById(id);
    if (info != null) {
    return Body.newInstance(info);
    }
    return Body.newInstance(CODE_470, "查询失败");
    }


    /**
    * 查询数据list
    *
    * @param
    */
    @PostMapping("findlist")
    public Body findlist() {
    List<${entity}> list = ${entity?uncap_first}Service.list();
    if (list != null && list.size() > 0) {
    return Body.newInstance(list);
    }
    return Body.newInstance(CODE_470, "查询失败");
    }

    /**
    * 分页查询数据
    *
    * @param
    */
    @PostMapping("page")
    public Body page(Integer current, Integer size) {
    Page<${entity}> pg = new Page<${entity}>(current, size);
    IPage<${entity}> list = ${entity?uncap_first}Service.page(pg);
    if (list != null && list.getSize() > 0) {
    return Body.newInstance(list);
    }
    return Body.newInstance(CODE_470, "查询失败");
    }
    }
</#if>
